
import 'package:basic_common/app_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_picker/picker.dart';
import 'package:flutter_pickers/pickers.dart';
import 'package:flutter_pickers/style/picker_style.dart';
import 'package:flutter_pickers/time_picker/model/pduration.dart';
import 'package:get/get.dart';
import 'screen_helper.dart';

/* 
 * @description: 底部滚动弹窗工具类
 * @author: Jane 
 * @date: 2023-09-19 14:21:16
 */
class BottomSheetTool {
  ///  单列数据
  /// dataList 数据列表
  /// selectDat选中数据
  /// onConfirm 确定选择事件
  static void singlePickerView(
      {required List dataList,
      required selectData,
      required Function(dynamic, int)? onConfirm}) {
    Pickers.showSinglePicker(Get.context!,
        data: dataList,
        selectData: selectData,
        onConfirm: onConfirm,
        pickerStyle: PickerStyle(
            commitButton: Padding(
          padding: EdgeInsets.only(right: ScreenHelper.width(10)),
          child: const Text(
            "确定",
            style: TextStyle(color: AppTheme.dartTextColor),
          ),
        )));
  }

  /// 日期选择
  static Future<String> datePickerView(
      {required dynamic Function(PDuration)? onConfirm}) async {
    String result = '';
    Pickers.showDatePicker(
      pickerStyle: PickerStyle(
          commitButton: Padding(
        padding: EdgeInsets.only(right: ScreenHelper.width(10)),
        child: const Text(
          "确定",
          style: TextStyle(color: AppTheme.dartTextColor),
        ),
      )),
      Get.context!,
      onConfirm: onConfirm,
      // onChanged: (p) {
      //   result= p.year!.toString()+"-"+p.month!.toString()+"-"+p.day!.toString();
      // }
    );
    return result;
  }

  /// 多级联动
  /// multidata
  static void showPicker(
      {required List<dynamic> keshiMaps, required List<dynamic> selectData}) {
//     // var multiData = {
//     //   '成人心脏外科':['内科'],
//     //   '儿科': ['口腔科', '小二科'],
//     //   '普通外科': ['心外科',"脑外科"]
//     // };
//     var multiData = {
//       'a': {
//         'aa': [1, 'ww'],
//         'aaa': 10086
//       },
//       'b': ['bbb', 'bbbbb'],
//       'c': {
//         'cc': {
//           'ccc333': [111, 1111],
//           'cccc33': {
//             'ccccc4': '帮忙star',
//             'ccc4-2': [4442, 44442, 442]
//           },
//         },
//         'cc2': ['ccc', 123],
//         'cc3': 'star 鼓励'
//       }
//     };

// // Map map=Map.fromIterable(keshiMaps, key: (v) {
// //   print("vvvvvvv=${v}");
// // } , value: (v) => v);
// ;
// // keshiMaps.asMap().map((index, element) => MapEntry(index, "$element $index")).values.toList();
// print("解析的===${multiData}");
// print("解析的===${keshiMaps}");

// print("解析的===${keshiMaps.toSet()}");

//     Pickers.showMultiLinkPicker(
//       Get.context!,
//       data: keshiMaps.toSet().toString(),
//       // 注意数据类型要对应 比如 44442 写成字符串类型'44442'，则找不到
//       // selectData: ['c', 'cc', 'cccc33', 'ccc4-2', 44442],
//       selectData: selectData.length==0?['','']:selectData,
//       // selectData: selectData,
//       columeNum: 2,
//       suffix: ['',''],
//       onConfirm: (List p, List n) {
//         print('longer >>> 返回数据：${p.join('、')}');
//         print('longer >>> 返回数据类型：${p.map((x) => x.runtimeType).toList()}');
//       },
//     );
  }

  /// labelKey 要查找的key
  static showPickerDialog(BuildContext context,
      {required String title,
      required List<dynamic> allkeshiMap,
      required List<dynamic> keshiMap,
      required List selectIdList,
      required List selectINameList,
      required String labelKey,
      required void Function(Picker, List<int>)? onConfirm}) {
    print(keshiMap);
    print(allkeshiMap);

    Picker(
            adapter: PickerDataAdapter<String>(pickerData: keshiMap),
            hideHeader: false,
            title: Text(''),
            confirmText: "确认",
            changeToFirst: true,
            confirmTextStyle: TextStyle(color: AppTheme.dartTextColor),
            cancelText: "取消",
            cancelTextStyle: TextStyle(color: AppTheme.hintTextColor),
            onConfirm: onConfirm)
        .showModal(context);
  }
}
